package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-29 17:37
 **/
public class LeetCode406 {

    public int[][] reconstructQueue(int[][] people) {
        //按身高降序排列,身高相同则按位置升序排雷
        Arrays.sort(people, (person1, person2) -> person1[0] != person2[0] ? person2[0] - person1[0] : person1[1] - person2[1]);
        int n = people.length;
        List<int[]> ans = new ArrayList<>();

        for (int[] person : people) {
            ans.add(person[1], person);
        }
        //列表转成数组返回
        return ans.toArray(new int[0][]);
    }

}
